var url = require("../../utils/url.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    wif: 0
  },

  onLoad: function () {
    var c = wx.getStorageSync('key');
    if (c) {
      this.setData({
        wif: 1,
        wifList: c
      })
    } else {
      this.setData({
        wif: 0
      })
    }
  },
  click_clear: function () {
    var that = this;
    wx.showModal({
      title: '注意',
      content: '您确定要清除历史记录吗？',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.clearStorage()
          that.setData({
            wif: 0
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  click_hidden: function () {
    this.setData({
      wif: 0
    })
  },
  click_navigate: function (e) {
    console.log(e.currentTarget.dataset);
    var id = e.currentTarget.dataset.id;
    var type = e.currentTarget.dataset.type;
    var value = e.currentTarget.dataset.value;
    wx.navigateTo({
      url: "/pages/details/details?id=" + id + "&type=" + type + "&value=" + value,
      success: function (res) {},
      fail: function (res) {},
      complete: function (res) {},
    })
    var arr = [];
    var c = wx.getStorageSync('key');
    console.log(c)
    if (c) {
      arr = c;
      for (var i = 0; i < c.length; i++) {
        if (c[i].id == e.currentTarget.dataset.id) {
          return
        }
      }
      arr.push(e.currentTarget.dataset);
      wx.setStorageSync('key', arr);
    } else {
      arr.push(e.currentTarget.dataset);
      wx.setStorageSync('key', arr);
    }
  },
  onclick: function (e) {
    var that = this;
    console.log("==", e.detail)
    if (e.detail.value == "") {
      return
    }
    var a = e.detail.value;
    url.search_data({
      q: e.detail.value,
      success: function (res) {
        console.log(res)
        that.setData({
          list: res.data.subjects
        })
      }
    })


  },
})